<template>
  <div class="t_title">
    <!-- 图片 -->
    <div class="ms">
      <img src="../assets/aa.jpg" />
    </div>
    <!-- 下拉框显示用户名 -->
    <div class="uu">
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          {{ name }}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="loginout"> 退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      name: ""
    };
  },
  //生命周期
  // 页面加载时进行调用
  created() {
    //从localStorage中获取数据
    var vo = localStorage.getItem("vo");
    //将字符串类型转换 为JSON
    var s = eval("(" + vo + ")");
    this.name = s.name;
  },
  mounted() {},
  watch: {},
  computed: {},
  methods: {
    handleCommand(command) {
      if (command == "loginout") {
        //退出
        localStorage.removeItem("vo");
        //跳转首页
        this.$router.push("/");
      }
    }
  }
};
</script>
<style scoped>
.t_title {
  display: flex;
  align-items: center;
  height: 70px;
  padding-right: 50px;
  float: right;
}
.ms {
  margin-top: 10px;
}
.ms img {
  width: 50px;
  height: 50px;
  border-radius: 50%;
}
.uu {
  margin-left: 20px;
}
</style>
